package graph;


import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;



public class Vertex {

    private String     name;   // Vertex name
    private HashSet<Edge> adj;    // Adjacent vertices
    //private double     dist;   // Cost
    //public Vertex     prev;   // Previous vertex on shortest path


    public Vertex(String n) {
        this.name = n;
        this.adj = new HashSet<Edge>();
    }

    public Set<Edge> getEdge() {
        Set<Edge> clonedList = new LinkedHashSet<Edge>();
        for (Edge e : adj) {
            clonedList.add(new Edge(e.getVertex1(), e.getVertex2(),
                    e.getCost()));
        }
        return clonedList;
    }

	/**
	 * Set adjacent edges.
	 * 
	 * @param edges The set of adjacent edges.
	 */
	public void setEdge(Set<Edge> edges){ //this method works just fine
		for (Edge e : edges){// for every edge in the set of edges passed
			String[] edge = e.toString().split(" ");
			// every edge toString is in the form: source dest cost
			//                                        0    1    2
			if (e.getVertex1().toString().equals(this.name) ||
				e.getVertex2().toString().equals(this.name))
			{
				adj.add(e);
			}
		}
	}
    
    public String toString() {
        return this.name;

    }

    public boolean equals(Vertex the_other){

        if(the_other != null)
            return (name.equals(the_other.name) );
        else return false;
    }

}
